<?php

namespace App;

class Conf
{
    private $conf = [];

    private static $instance;

    private function __construct()
    {
        $confFiles = glob(CONF_PATH . DS . "*.php");
        foreach ($confFiles as $file) {
            $confArr = require $file;
            $this->conf = array_merge($this->conf, $confArr);
        }
    }


    private function __clone()
    {
        // TODO: Implement __clone() method.
    }


    public static function getInstance()
    {
        if (self::$instance == null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * @return array
     */
    public function getConf()
    {
        return $this->conf;
    }


    public static function get($key = "")
    {
        $conf = self::getInstance()->getConf();

        if ($key) {
            $keyArr = explode('.', $key);

            foreach ($keyArr as $key) {
                $conf = $conf[$key] ?? [];
            }
        }
        return $conf;
    }
}